home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / Main.as < prev    next >
Text File  |  2007-09-27  |  12KB  |  319 lines

  1. class Main extends Library.DispatcherBase
  2. {
  3.    static var SOUND_VOL_SOUND = 100;
  4.    static var SOUND_VOL_MUSIC = 35;
  5.    static var SOUND_CAT_SOUND = "SFX";
  6.    static var SOUND_CAT_MUSIC = "Music";
  7.    static var LOSE_REASON_TIMEOUT = 1;
  8.    static var LOSE_REASON_MOONSTONES = 2;
  9.    static var LOSE_REASON_QUIT = 3;
  10.    static var FRAME_RATE = 36;
  11.    static var SECTION_TITLE = "Title";
  12.    static var SECTION_INSTRUCTIONS = "Instructions";
  13.    static var SECTION_GAME = "Game";
  14.    static var SECTION_WIN = "Win";
  15.    static var SECTION_LOSE = "Lose";
  16.    static var SECTION_HIGHSCORE = "HighScore";
  17.    function Main(__mcRef)
  18.    {
  19.       super();
  20.       this.mcRef = __mcRef;
  21.       Main.oCtrl = this;
  22.       this.oHS = new NickHS();
  23.       this.nLatestScore = 0;
  24.       this.bHSFromTitle = true;
  25.       this.bHSScrolling = false;
  26.       this.mcRef.onEnterFrame = Library.Utils.Delegate.create(this,this.doEnterFrame);
  27.       Library.Sound.SoundManager.doInit(this.mcRef);
  28.       Library.Sound.SoundManager.setCategoryVolume(Main.SOUND_CAT_SOUND,Main.SOUND_VOL_SOUND);
  29.       Library.Sound.SoundManager.setCategoryVolume(Main.SOUND_CAT_MUSIC,Main.SOUND_VOL_MUSIC);
  30.       this.doStartPackMusic();
  31.       this.oTransition = new Library.Transition(this.mcRef.mcTransition);
  32.       this.oTransition.__set__Listener(this);
  33.       this.doAddListener(this.oTransition);
  34.       this.oCodeBox = new CodeBox();
  35.       this.doTransitionTo(Main.SECTION_TITLE);
  36.    }
  37.    static function get Instance()
  38.    {
  39.       return Main.oCtrl;
  40.    }
  41.    function get StageRoot()
  42.    {
  43.       return this.mcRef;
  44.    }
  45.    function doEnterFrame()
  46.    {
  47.       super.doEnterFrame();
  48.       if(this.bHSScrolling)
  49.       {
  50.          this.mcRef.mcState.mcHS.txtHSNumber.scroll += this.nHSScrollChange;
  51.          this.mcRef.mcState.mcHS.txtHSName.scroll += this.nHSScrollChange;
  52.          this.mcRef.mcState.mcHS.txtHSScore.scroll += this.nHSScrollChange;
  53.       }
  54.    }
  55.    function doRollSound()
  56.    {
  57.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Button_Roll.mp3",100,1,true);
  58.    }
  59.    function doClickSound()
  60.    {
  61.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Button_Click.mp3",100,1,true);
  62.    }
  63.    function doShowHighScoresFromTitle()
  64.    {
  65.       this.bHSFromTitle = true;
  66.       this.doTransitionTo(Main.SECTION_HIGHSCORE);
  67.    }
  68.    function onBackToTitle()
  69.    {
  70.       this.doTransitionTo(Main.SECTION_TITLE);
  71.    }
  72.    function onPlayerLose(__nLoseReason)
  73.    {
  74.       this.nLoseReason = __nLoseReason;
  75.       this.doTransitionTo(Main.SECTION_LOSE);
  76.    }
  77.    function onPlayerWin()
  78.    {
  79.       this.doTransitionTo(Main.SECTION_WIN);
  80.    }
  81.    function doPlayGame(__bStoryMode)
  82.    {
  83.       this.bTargetModeStory = __bStoryMode;
  84.       this.doTransitionTo(Main.SECTION_GAME);
  85.    }
  86.    function onTransitionEvent(__nEvent, __oTransition)
  87.    {
  88.       switch(__nEvent)
  89.       {
  90.          case Library.Transition.TRANSITION_SCREEN_COVERED:
  91.             this.doUnloadSection(this.sCurrentSection);
  92.             this.doSetSection(this.sTargetSection);
  93.             Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"transition_out.mp3",60);
  94.             break;
  95.          case Library.Transition.TRANSITION_COMPLETE:
  96.       }
  97.    }
  98.    function doSoundEvent(__nEvent, __oSound)
  99.    {
  100.       if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
  101.       {
  102.          if(__oSound == this.oMusicPack)
  103.          {
  104.             delete this.oMusicPack;
  105.          }
  106.       }
  107.    }
  108.    function doSubmitScoreAndRefresh()
  109.    {
  110.       this.doSubmitScore();
  111.       this.bHSFromTitle = false;
  112.       var _loc2_ = [0.55059,0.39611,0.0533,0,0,0.20059,0.74611,0.0533,0,0,0.20059,0.39611,0.4033,0,0,0,0,0,1,0];
  113.       var _loc3_ = new flash.filters.ColorMatrixFilter(_loc2_);
  114.       this.mcRef.mcState.mcButtons.btnSubmitHS.filters = [_loc3_];
  115.       this.mcRef.mcState.mcButtons.btnSubmitHS.enabled = false;
  116.    }
  117.    function doSubmitAndListScore()
  118.    {
  119.       this.doSubmitScore();
  120.       this.bHSFromTitle = false;
  121.       this.doTransitionTo(Main.SECTION_HIGHSCORE);
  122.    }
  123.    function doStartPackMusic()
  124.    {
  125.       if(this.oMusicPack == undefined)
  126.       {
  127.          this.oMusicPack = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_MUSIC,"Packaging.wav",0,999999);
  128.          this.oMusicPack.doAddListener(this);
  129.       }
  130.       this.oMusicPack.doFadeTo(100);
  131.    }
  132.    function doStopPackMusic()
  133.    {
  134.       if(this.oMusicPack != undefined)
  135.       {
  136.          this.oMusicPack.doFadeTo(0);
  137.       }
  138.    }
  139.    function doStopScrollHsList()
  140.    {
  141.       this.bHSScrolling = false;
  142.    }
  143.    function doStartScrollHsList(__nChange)
  144.    {
  145.       this.bHSScrolling = true;
  146.       this.nHSScrollChange = __nChange;
  147.    }
  148.    function doInstructionPageChange(__nChange)
  149.    {
  150.       this.mcRef.mcState.gotoAndStop(this.mcRef.mcState._currentframe + __nChange);
  151.       this.doSetUpInstructions();
  152.    }
  153.    function get HSM()
  154.    {
  155.       return this.oHS;
  156.    }
  157.    function get CodeBoxManager()
  158.    {
  159.       return this.oCodeBox;
  160.    }
  161.    function doSubmitScore()
  162.    {
  163.       this.oHS.bSubmitHS = true;
  164.       this.oHS.submitScore(this.nLatestScore);
  165.       this.mcRef.mcState.btnSubmitHS._visible = false;
  166.    }
  167.    function doSetUpTitle()
  168.    {
  169.       this.mcRef.mcState.btnPlayStory.onRelease = Library.Utils.Delegate.create(this,this.doPlayGame,true);
  170.       this.mcRef.mcState.btnPlayUser.onRelease = Library.Utils.Delegate.create(this,this.doPlayGame,false);
  171.       this.mcRef.mcState.btnInstructions.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_INSTRUCTIONS);
  172.       this.mcRef.mcState.btnViewHS.onRelease = Library.Utils.Delegate.create(this,this.doShowHighScoresFromTitle);
  173.       this.oCodeBox.setBox(this.mcRef.mcState.mcCode);
  174.    }
  175.    function doSetUpHS()
  176.    {
  177.       if(this.bHSFromTitle)
  178.       {
  179.          this.mcRef.mcState.mcButtons.gotoAndStop("Back");
  180.          this.mcRef.mcState.mcButtons.btnBack.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_TITLE);
  181.       }
  182.       else
  183.       {
  184.          this.mcRef.mcState.mcButtons.gotoAndStop("PlayAgain");
  185.          this.mcRef.mcState.mcButtons.btnPlayAgain.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_GAME);
  186.       }
  187.       if(!this.bHSFromTitle)
  188.       {
  189.          this.mcRef.mcState.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nLatestScore,9);
  190.       }
  191.       else
  192.       {
  193.          this.mcRef.mcState.txtScore._visible = false;
  194.          this.mcRef.mcState.mcScoreLabel._visible = false;
  195.       }
  196.       this.oHS.setHSBoard(this.mcRef.mcState.mcHS);
  197.       this.oHS.getScores();
  198.       if(this.oHS.bSubmitHS || !this.oHS.getIsLoggedIn() || this.bHSFromTitle)
  199.       {
  200.          this.mcRef.mcState.mcButtons.btnSubmitHS.useHandCursor = false;
  201.          var _loc2_ = [0.55059,0.39611,0.0533,0,0,0.20059,0.74611,0.0533,0,0,0.20059,0.39611,0.4033,0,0,0,0,0,1,0];
  202.          var _loc3_ = new flash.filters.ColorMatrixFilter(_loc2_);
  203.          this.mcRef.mcState.mcButtons.btnSubmitHS.filters = [_loc3_];
  204.          this.mcRef.mcState.mcButtons.btnSubmitHS.enabled = false;
  205.       }
  206.       else
  207.       {
  208.          this.mcRef.mcState.mcButtons.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitScoreAndRefresh);
  209.       }
  210.       this.mcRef.mcState.btnHaut.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,-1);
  211.       this.mcRef.mcState.btnBas.onPress = Library.Utils.Delegate.create(this,this.doStartScrollHsList,1);
  212.       this.mcRef.mcState.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  213.       this.mcRef.mcState.btnHaut.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  214.       this.mcRef.mcState.btnHaut.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  215.       this.mcRef.mcState.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  216.       this.mcRef.mcState.btnBas.onReleaseOutside = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  217.       this.mcRef.mcState.btnBas.onRollOut = Library.Utils.Delegate.create(this,this.doStopScrollHsList);
  218.    }
  219.    function doSetUpLose()
  220.    {
  221.       this.doSetUpWinLoseShared();
  222.       if(this.nLatestPlayMode == BaseLevelData.LEVEL_TYPE_USER)
  223.       {
  224.          this.mcRef.mcState.mcScore._visible = false;
  225.       }
  226.       this.mcRef.mcState.mcReason.gotoAndStop(this.nLoseReason);
  227.    }
  228.    function doSetUpWin()
  229.    {
  230.       this.doSetUpWinLoseShared();
  231.    }
  232.    function doSetUpWinLoseShared()
  233.    {
  234.       this.bHSFromTitle = false;
  235.       if(this.nLatestPlayMode == BaseLevelData.LEVEL_TYPE_STORY)
  236.       {
  237.          this.mcRef.mcState.btnViewHS.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_HIGHSCORE);
  238.          if(this.oHS.getIsLoggedIn())
  239.          {
  240.             this.mcRef.mcState.btnSubmitHS.onRelease = Library.Utils.Delegate.create(this,this.doSubmitAndListScore);
  241.          }
  242.          else
  243.          {
  244.             this.mcRef.mcState.btnSubmitHS._visible = false;
  245.             this.mcRef.mcState.mcCorde1._visible = false;
  246.          }
  247.       }
  248.       else
  249.       {
  250.          this.mcRef.mcState.btnViewHS._visible = false;
  251.          this.mcRef.mcState.btnSubmitHS._visible = false;
  252.          this.mcRef.mcState.mcCorde1._visible = false;
  253.          this.mcRef.mcState.mcCorde2._visible = false;
  254.          this.mcRef.mcState.mcSign._visible = false;
  255.       }
  256.       this.mcRef.mcState.mcScore.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nLatestScore,9);
  257.       this.mcRef.mcState.btnPlayAgain.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_GAME);
  258.    }
  259.    function doSetUpInstructions()
  260.    {
  261.       this.mcRef.mcState.stop();
  262.       this.mcRef.mcState.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Main.SECTION_TITLE);
  263.       this.mcRef.mcState.btnNext.onRelease = Library.Utils.Delegate.create(this,this.doInstructionPageChange,1);
  264.       this.mcRef.mcState.btnBack.onRelease = Library.Utils.Delegate.create(this,this.doInstructionPageChange,-1);
  265.    }
  266.    function doCreateGame()
  267.    {
  268.       this.oGame = new Game(this.mcRef.mcState,this.bTargetModeStory);
  269.    }
  270.    function doUnloadGame()
  271.    {
  272.       this.nLatestPlayMode = this.oGame.LevelType;
  273.       if(this.nLatestScore > this.oGame.__get__Score())
  274.       {
  275.          this.oHS.bSubmitHS = false;
  276.       }
  277.       this.nLatestScore = this.oGame.Score;
  278.       this.oGame.doDestroy();
  279.    }
  280.    function doSetSection(__sSection)
  281.    {
  282.       this.sCurrentSection = __sSection;
  283.       this.mcRef.gotoAndStop(this.sCurrentSection);
  284.       switch(this.sCurrentSection)
  285.       {
  286.          case Main.SECTION_WIN:
  287.             this.doSetUpWin();
  288.             break;
  289.          case Main.SECTION_LOSE:
  290.             this.doSetUpLose();
  291.             break;
  292.          case Main.SECTION_INSTRUCTIONS:
  293.             this.doSetUpInstructions();
  294.             break;
  295.          case Main.SECTION_TITLE:
  296.             this.doSetUpTitle();
  297.             break;
  298.          case Main.SECTION_GAME:
  299.             this.doCreateGame();
  300.             break;
  301.          case Main.SECTION_HIGHSCORE:
  302.             this.doSetUpHS();
  303.       }
  304.    }
  305.    function doUnloadSection(__sSection)
  306.    {
  307.       if(__sSection === Main.SECTION_GAME)
  308.       {
  309.          this.doUnloadGame();
  310.       }
  311.    }
  312.    function doTransitionTo(__sSection)
  313.    {
  314.       this.sTargetSection = __sSection;
  315.       this.oTransition.doStart();
  316.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"transition_in.mp3",60);
  317.    }
  318. }
  319.